package fr.univnantes.lina.ftbcleaner;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import fr.univnantes.lina.ftbcleaner.FTBPropertiesMultiWordAsSingleWordSequenceSearcher;
import fr.univnantes.lina.ftbcleaner.FTBXMLSingleWordSaxHandler;
import fr.univnantes.lina.ftbcleaner.WordAttributes;
import fr.univnantes.lina.ftbcleaner.WordForms;

public class FTBPropertiesSingleWordCollector extends
		FTBPropertiesMultiWordAsSingleWordSequenceSearcher {

	public FTBPropertiesSingleWordCollector() {
		super();
	}

	/**
	 * Compute stats from sw occurrences
	 * @param aWordForms TODO
	 *   
	 */
	public List<WordAttributes> collectPropertiesFromSimpleWordNodesSax(File inputFile,
			WordForms aWordForms) {
			
				SAXParserFactory parserFactory = SAXParserFactory.newInstance();
			
				FTBXMLSingleWordSaxHandler handler = new FTBXMLSingleWordSaxHandler (aWordForms);
			
				//try {
				SAXParser parser = null;
				try {
					parser = parserFactory.newSAXParser();
				} catch (ParserConfigurationException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (SAXException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
				try {
					//xmlStream.setEncoding("UTF-8");
					parser.parse(inputFile, handler);
				} catch (SAXException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				//} catch (Exception e) {
				//	throw new AnalysisEngineProcessException(e);
				//}
			
				return handler.getSingleWordOccAttributesList() ;
			}

}